package com.suxin.handler;

import org.slf4j.MDC;

import java.util.Map;

/**
 * @author Tang
 * @classname MDCRunnable
 * @description [  ]
 * @date 2023/2/24 21:36
 */
public class MDCRunnable implements Runnable {

    private final Runnable runnable;

    private final Map<String, String> map;

    public MDCRunnable(Runnable runnable) {
        this.runnable = runnable;
        // 保存当前线程的值
        this.map = MDC.getCopyOfContextMap();
    }

    @Override
    public void run() {
        // 设置到子线程中
        MDC.setContextMap(this.map);
        runnable.run();
    }

}
